package cn.hubujyjs.mooc.controller;


import cn.hubujyjs.mooc.common.Result;
import cn.hubujyjs.mooc.entity.Course;
import cn.hubujyjs.mooc.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Huang Jintao
 * @since 2022-11-15
 */
@RestController
@RequestMapping("/api/course")
@Api(tags = "课程接口")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @ApiOperation("添加课程")
    @PostMapping("/addCourse")
    public Result addCourse(@RequestBody Course course){
        courseService.addCourse(course);
        return Result.success();
    }
    @ApiOperation("按播放量的课程列表(热榜)")
    @GetMapping("/listByViewCount")
    public Result<List<Course>> listByViewCount(){
        List<Course> courseList=courseService.listByViewCount();
        return Result.success(courseList);
    }
    @ApiOperation("播放量加一")
    @PostMapping("/addViewCount")
    public Result addViewCount(Long id){
        courseService.addViewCount(id);
        return Result.success();
    }
    @ApiOperation("根据id获取课程")
    @GetMapping("/getCourseById/{id}")
    public Result<Course> getCourseById(@PathVariable Long id){
        Course byId = courseService.getById(id);
        return Result.success(byId);
    }
}

